package com.sugar.real.estate.module.business.controller.app.openedcity;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.module.business.controller.app.infocls.vo.AppGetCityRespVO;
import com.sugar.real.estate.module.business.controller.app.infocls.vo.AppOpenedCityRespVO;
import com.sugar.real.estate.module.business.service.openedcity.OpenedCityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 已开通城市")
@RestController
@RequestMapping("/biz/opened-city")
@Validated
public class AppOpenedCityController {

    @Resource
    private OpenedCityService openedCityService;

    @GetMapping("/city/list")
    @Operation(summary = "仅获取已开通城市")
    @PermitAll
    public CommonResult<AppGetCityRespVO> getTopOpenedCity() {
        return success(openedCityService.getTopOpenedCity());
    }

    @GetMapping("/city/{parentId}/list")
    @Operation(summary = "根据父级ID获取子级")
    @PermitAll
    public CommonResult<List<AppOpenedCityRespVO>> getOpenedCityByParentId(@PathVariable("parentId") Long parentId) {
        return success(openedCityService.getOpenedCityByParentId(parentId));
    }

    @GetMapping("/tree")
    @Operation(summary = "获得全部（树形）")
    @PermitAll
    public CommonResult<AppGetCityRespVO> getOpenedCityTreeList() {
        return success(openedCityService.getOpenedCityTreeList());
    }
}